package zhoufu.sz.sanxiao_check.ui.train;

import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import java.util.ArrayList;
import java.util.Arrays;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.databinding.ActivityTrainDetailsBinding;
import zhoufu.sz.sanxiao_check.models.TrainListModel;
import zhoufu.sz.sanxiao_check.ui.BaseActivity;
import zhoufu.sz.sanxiao_check.ui.adapter.GridAdapter;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/8/4
 */
public class TrainDetailsActivity extends BaseActivity implements AdapterView.OnItemClickListener
{
    ActivityTrainDetailsBinding _binding;

    private TrainListModel model;


    @Override protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setTitle("培训详情");
        model = getIntent().getParcelableExtra("TrainListModel");
        if ( savedInstanceState != null )
        {
            model = savedInstanceState.getParcelable("TrainListModel");
        }
        _binding.setModel(model);

        GridAdapter adapter = new GridAdapter(this, new ArrayList<String>(),
                R.layout.item_imageview, false);
        adapter.replaceAll(Arrays.asList(TextUtils.split(model.getImgs(), ",")));
        _binding.mGridView.setAdapter(adapter);
        _binding.mGridView.setOnItemClickListener(this);
    }

    @Override protected void initInject()
    {

    }

    @Override protected void initAfterOnCreate(ViewDataBinding binding)
    {
        _binding = (ActivityTrainDetailsBinding) binding;
    }

    @Override protected int setIndividualId()
    {
        return R.layout.activity_train_details;
    }

    @Override protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.putParcelable("TrainListModel", model);
    }

    @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        _navigator.startShowPic(this, _binding.getModel().getImgs());
    }
}
